class Animal():

    __slots__ = ('name')
    def __str__(self):
        return f'name:{self.name}'
    
class Dog(Animal):
    __slots__ = ('age') # 声明__slots__属性后，会跟父类的__slots__属性合并后实际为：('age','name')
   

dog = Dog()
dog.name = 'dog'
dog.age=10
print(dog)


class Cat(Animal):
    __slots__ = () # 声明__slots__属性后，会跟父类的__slots__属性合并后实际为：('name')

cat = Cat()
cat.name = 'cat'
try:
    print(cat.age)
except AttributeError as e:
    print(e)

# 没有声明__slots__属性，就不会继承父类的__slots__属性
class Bird(Animal):
   pass

bird = Bird()
bird.name="bird"
bird.age=10
bird.size=20
print(f'bird name:{bird.name},age:{bird.age},size:{bird.size}')


